<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="死亡日期" prop="deathData">
        <el-date-picker clearable
          v-model="queryParams.deathData"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择死亡日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最近一次结算日期" prop="settleData">
        <el-date-picker clearable
          v-model="queryParams.settleData"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最近一次结算日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="涉及医疗总费用" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入涉及医疗总费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涉及基金金额" prop="fund">
        <el-input
          v-model="queryParams.fund"
          placeholder="请输入涉及基金金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员id" prop="personnel">
        <el-input
          v-model="queryParams.personnel"
          placeholder="请输入人员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省级医保区划" prop="provCode">
        <el-input
          v-model="queryParams.provCode"
          placeholder="请输入省级医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市省级医保区划" prop="cityCode">
        <el-input
          v-model="queryParams.cityCode"
          placeholder="请输入市省级医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在医保区划" prop="distCode">
        <el-input
          v-model="queryParams.distCode"
          placeholder="请输入所在医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省级医保区划" prop="provName">
        <el-input
          v-model="queryParams.provName"
          placeholder="请输入省级医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市省级医保区划" prop="cityName">
        <el-input
          v-model="queryParams.cityName"
          placeholder="请输入市省级医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在医保区划" prop="distName">
        <el-input
          v-model="queryParams.distName"
          placeholder="请输入所在医保区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核查情况" prop="checkType">
        <el-select v-model="queryParams.checkType" placeholder="请选择核查情况" clearable>
          <el-option
            v-for="dict in dict.type.check_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="核查人员" prop="checkPerson">
        <el-input
          v-model="queryParams.checkPerson"
          placeholder="请输入核查人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核查说明" prop="checkRemake">
        <el-input
          v-model="queryParams.checkRemake"
          placeholder="请输入核查说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核查结果" prop="checkResults">
        <el-input
          v-model="queryParams.checkResults"
          placeholder="请输入核查结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['person:death:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-message"
          size="mini"
          @click="handleAdd"

        >下发经办核查</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['person:death:edit']"
        >修改</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['person:death:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['person:death:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deathList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="死亡日期" align="center" prop="deathData" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deathData, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最近一次结算日期" align="center" prop="settleData" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.settleData, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="涉及医疗总费用" align="center" prop="amount" />
      <el-table-column label="涉及基金金额" align="center" prop="fund" />
      <el-table-column label="人员id" align="center" prop="personnel" />
      <el-table-column label="省级医保区划" align="center" prop="provCode" />
      <el-table-column label="市省级医保区划" align="center" prop="cityCode" />
      <el-table-column label="所在医保区划" align="center" prop="distCode" />
      <el-table-column label="省级医保区划" align="center" prop="provName" />
      <el-table-column label="市省级医保区划" align="center" prop="cityName" />
      <el-table-column label="所在医保区划" align="center" prop="distName" />
      <el-table-column label="死亡证明" align="center" prop="deathCertificate" />
      <el-table-column label="核查情况" align="center" prop="checkType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.check_type" :value="scope.row.checkType"/>
        </template>
      </el-table-column>
      <el-table-column label="核查人员" align="center" prop="checkPerson" />
      <el-table-column label="核查说明" align="center" prop="checkRemake" />
      <el-table-column label="核查结果" align="center" prop="checkResults">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.check_results" :value="scope.row.checkResults"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['person:death:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
          >详情</el-button>


          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['person:death:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改死亡骗保对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="死亡日期" prop="deathData">
          <el-date-picker clearable
            v-model="form.deathData"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择死亡日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最近一次结算日期" prop="settleData">
          <el-date-picker clearable
            v-model="form.settleData"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最近一次结算日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="涉及医疗总费用" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入涉及医疗总费用" />
        </el-form-item>
        <el-form-item label="涉及基金金额" prop="fund">
          <el-input v-model="form.fund" placeholder="请输入涉及基金金额" />
        </el-form-item>
        <el-form-item label="人员id" prop="personnel">
          <el-input v-model="form.personnel" placeholder="请输入人员id" />
        </el-form-item>
        <el-form-item label="省级医保区划" prop="provCode">
          <el-input v-model="form.provCode" placeholder="请输入省级医保区划" />
        </el-form-item>
        <el-form-item label="市省级医保区划" prop="cityCode">
          <el-input v-model="form.cityCode" placeholder="请输入市省级医保区划" />
        </el-form-item>
        <el-form-item label="所在医保区划" prop="distCode">
          <el-input v-model="form.distCode" placeholder="请输入所在医保区划" />
        </el-form-item>
        <el-form-item label="省级医保区划" prop="provName">
          <el-input v-model="form.provName" placeholder="请输入省级医保区划" />
        </el-form-item>
        <el-form-item label="市省级医保区划" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入市省级医保区划" />
        </el-form-item>
        <el-form-item label="所在医保区划" prop="distName">
          <el-input v-model="form.distName" placeholder="请输入所在医保区划" />
        </el-form-item>
        <el-form-item label="死亡证明" prop="deathCertificate">
          <el-input v-model="form.deathCertificate" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="核查情况" prop="checkType">
          <el-select v-model="form.checkType" placeholder="请选择核查情况">
            <el-option
              v-for="dict in dict.type.check_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="核查人员" prop="checkPerson">
          <el-input v-model="form.checkPerson" placeholder="请输入核查人员" />
        </el-form-item>
        <el-form-item label="核查说明" prop="checkRemake">
          <el-input v-model="form.checkRemake" placeholder="请输入核查说明" />
        </el-form-item>
        <el-form-item label="核查结果" prop="checkResults">
          <el-input v-model="form.checkResults" placeholder="请输入核查结果" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



  <!-- 任务日志详细 -->
  <el-dialog title="详细" :visible.sync="openView" width="700px" append-to-body>
    <el-form ref="formd" :model="formd" label-width="120px" size="mini">
      <el-row>
        <el-col :span="12">
          <el-form-item   label="姓名：">{{ formd.name }}</el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item  label="死亡日期：">{{ formd.deathData }}</el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item  label="最近一次结算日期：">{{ formd.settleData }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  label="涉及医疗总费用：">{{ formd.amount }}</el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item  label="涉及基金金额：">{{ formd.fund }}</el-form-item>
        </el-col>


        <el-col :span="12">
          <el-form-item  label="所在医保区划：">{{ formd.cityName }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  label="核查人员：">{{ formd.checkPerson }}</el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item  label="核查说明：">{{ formd.checkRemake }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="核查结果：">
            <div v-if="formd.checkResults == '0'">属于骗保</div>
            <div v-else-if="formd.checkResults == '1'">不属于骗保</div>
            <div v-else-if="formd.checkResults == '2'">其他</div>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="openView = false">关 闭</el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>
import { listDeath, getDeath, delDeath, addDeath, updateDeath } from "@/api/person/death";

export default {
  name: "Death",
  dicts: ['check_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      openView: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 死亡骗保表格数据
      deathList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        deathData: null,
        settleData: null,
        amount: null,
        fund: null,
        personnel: null,
        provCode: null,
        cityCode: null,
        distCode: null,
        provName: null,
        cityName: null,
        distName: null,
        deathCertificate: null,
        checkType: null,
        checkPerson: null,
        checkRemake: null,
        checkResults: null
      },
      // 表单参数
      form: {},
      formd: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        deathData: [
          { required: true, message: "死亡日期不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "涉及医疗总费用不能为空", trigger: "blur" }
        ],
        fund: [
          { required: true, message: "涉及基金金额不能为空", trigger: "blur" }
        ],
        checkType: [
          { required: true, message: "核查情况不能为空", trigger: "change" }
        ],
        checkPerson: [
          { required: true, message: "核查人员不能为空", trigger: "blur" }
        ],
        checkRemake: [
          { required: true, message: "核查说明不能为空", trigger: "blur" }
        ],
        checkResults: [
          { required: true, message: "核查结果不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询死亡骗保列表 */
    getList() {
      this.loading = true;
      listDeath(this.queryParams).then(response => {
        this.deathList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        deathData: null,
        settleData: null,
        amount: null,
        fund: null,
        personnel: null,
        provCode: null,
        cityCode: null,
        distCode: null,
        provName: null,
        cityName: null,
        distName: null,
        deathCertificate: null,
        checkType: null,
        checkPerson: null,
        checkRemake: null,
        checkResults: null
      };
      this.resetForm("form");
      this.formd = {
        id: null,
        name: null,
        deathData: null,
        settleData: null,
        amount: null,
        fund: null,
        personnel: null,
        provCode: null,
        cityCode: null,
        distCode: null,
        provName: null,
        cityName: null,
        distName: null,
        deathCertificate: null,
        checkType: null,
        checkPerson: null,
        checkRemake: null,
        checkResults: null
      };
      this.resetForm("formd");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加死亡骗保";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDeath(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改死亡骗保";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDeath(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDeath(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除死亡骗保编号为"' + ids + '"的数据项？').then(function() {
        return delDeath(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleDetail(row,width, height) {
      const id = row.id || this.ids
      getDeath(id).then(response => {
        this.formd = response.data;
        this.openView = true;
        this.title = "死亡骗保详情";
      });

    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('person/death/export', {
        ...this.queryParams
      }, `death_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
